package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.data.EquipmentCategory;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IEquipmentCategoryDao;

/**
 * 
 * @author longshaohang
 * 
 */
@Repository("equipmentCategoryDao")
public class EquipmentCategoryDaoImpl implements IEquipmentCategoryDao {

	private static final String DELETED = "deleted";
	
	@Resource(name = "baseDao")
	private IBaseDao<EquipmentCategory> baseDao;

	@Override
	public void save(EquipmentCategory category) {
		baseDao.save(category);
	}

	@Override
	public EquipmentCategory update(EquipmentCategory category) {
		return baseDao.update(category);
	}

	@Override
	public EquipmentCategory queryById(long id) {
		return baseDao.queryById(EquipmentCategory.class, id);
	}

	@Override
	public List<EquipmentCategory> queryAll() {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();
		// 拼接sql语句
		hql.append("from EquipmentCategory where ");
		hql.append(DELETED + "=0");
		return baseDao.query(hql.toString());
		//return baseDao.queryList("EquipmentCategory");
	}

	@Override
	public EquipmentCategory queryByType(String type) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();
		// 拼接sql语句
		hql.append("from EquipmentCategory a where ");
		hql.append(" a.type='");
		hql.append(type + "'" );
		hql.append(" and ");
		hql.append(DELETED + "=0");
		return baseDao.queryObject(hql.toString());
	}

}
